@@ -0,0 +1,39 @@  | 
            ||
| 1 | 
                +# -*- coding: utf-8 -*-  | 
            |
| 2 | 
                +  | 
            |
| 3 | 
                +import os  | 
            |
| 4 | 
                +  | 
            |
| 5 | 
                +from django_six import CompatibilityBaseCommand  | 
            |
| 6 | 
                +  | 
            |
| 7 | 
                +from utils.qiniucdn import upload_file_path  | 
            |
| 8 | 
                +  | 
            |
| 9 | 
                +  | 
            |
| 10 | 
                +class Command(CompatibilityBaseCommand):  | 
            |
| 11 | 
                + def handle(self, *args, **options):  | 
            |
| 12 | 
                +  | 
            |
| 13 | 
                + dirs = ['media/salesman', 'media/user/member_activity', 'media/qn']  | 
            |
| 14 | 
                +  | 
            |
| 15 | 
                + for dir in dirs:  | 
            |
| 16 | 
                + for root, dirs, files in os.walk(dir):  | 
            |
| 17 | 
                +                print('')
               | 
            |
| 18 | 
                +                print('Root: {}'.format(root))
               | 
            |
| 19 | 
                +                print('Dirs: {}'.format(dirs))
               | 
            |
| 20 | 
                +                print('Files: {}'.format(files))
               | 
            |
| 21 | 
                + if not dirs and not files:  | 
            |
| 22 | 
                + os.rmdir(root)  | 
            |
| 23 | 
                + for file in files:  | 
            |
| 24 | 
                +                    print('  >> File: {}'.format(file))
               | 
            |
| 25 | 
                +                    ext = file.split('.')[-1]
               | 
            |
| 26 | 
                + if not ext:  | 
            |
| 27 | 
                + continue  | 
            |
| 28 | 
                + if ext.lower() not in ['jpg', 'jpeg', 'png', 'heic']:  | 
            |
| 29 | 
                + continue  | 
            |
| 30 | 
                + try:  | 
            |
| 31 | 
                +                        file_path = '{}/{}'.format(root, file)
               | 
            |
| 32 | 
                + if os.path.exists(file_path):  | 
            |
| 33 | 
                +                            qiniu_key = 'uncompressed/{}'.format(file_path)
               | 
            |
| 34 | 
                +                            print('    >> File Path: {}'.format(file_path))
               | 
            |
| 35 | 
                +                            print('    >> Qiniu Path: {}'.format(qiniu_key))
               | 
            |
| 36 | 
                + upload_file_path(file_path, key=qiniu_key, bucket='tamron', compress=False)  | 
            |
| 37 | 
                + os.remove(file_path)  | 
            |
| 38 | 
                + except Exception:  | 
            |
| 39 | 
                + pass  |